package com.karst.webnotes.chapter03
{
	import flash.events.Event;
	
	import org.aswing.AsWingManager;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.view.BasicView;
	
	internal class CubeExample extends BasicView
	{
		public function CubeExample()
		{
			super() ;
			createView() ;
			startRendering() ;
		}
		
		private var materials : MaterialsList = null ;
		private var cube : Cube  = null ; // 平面
		private function createView() : void
		{
			if( materials == null )
			{
				var red : ColorMaterial = new ColorMaterial( 0xFF0000 ) ; //声明并创建单色材质
				var blue : ColorMaterial = new ColorMaterial( 0x0000FF ) ;
				var green : ColorMaterial = new ColorMaterial( 0x00FF00 ) ;
				materials = new MaterialsList() ;  //声明并创建列表材质
				materials.addMaterial( red, "front" ) ;  //将单色材质加入列表材质
				materials.addMaterial( red, "back" ) ;
				materials.addMaterial( blue, "left" ) ;
				materials.addMaterial( blue, "right" ) ;
				materials.addMaterial( green, "top" ) ;
				materials.addMaterial( green, "bottom" ) ;
			}
			
			if( cube == null )
				cube = new Cube( materials, 300, 400, 300 ) ;

			scene.addChild( cube ) ;
		}
		
		override protected function onRenderTick( event : Event = null ) : void
		{
			super.onRenderTick() ;
			if( cube )
			{
				cube.localRotationY-- ;
				cube.localRotationZ-- ;
			}
		}
	}
}